package com.husd.leetcode.entry;

/**
 * 树的表示方法
 * <p>
 * 这个是二叉搜索树的节点
 *
 * @author hushengdong
 * @create 2019-10-30 16:35:00
 */
public class TreeNode {

    public Integer value;
    public TreeNode left;
    public TreeNode right;

    //二叉搜索树没用这个属性，红黑树用到了。
    public TreeNode pre;

    public ColorEnum color = ColorEnum.BLACK;

    public boolean isRed() {
        return this.color == ColorEnum.RED;
    }

    public boolean isBlack() {
        return this.color == ColorEnum.BLACK;
    }

    public void setRed() {

        this.color = ColorEnum.RED;
    }

    public void setBlack() {

        this.color = ColorEnum.BLACK;
    }

    public TreeNode() {
    }

    public TreeNode(Integer value) {
        this.value = value;
    }

    public TreeNode(Integer value, ColorEnum color) {
        this.value = value;
        this.color = color;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.value = val;
        this.left = left;
        this.right = right;
    }

    public String value2String() {
        if (isRed()) {
            return "R" + String.valueOf(value);
        }
        return String.valueOf(value);
    }

    @Override
    public String toString() {

        return value2String();
    }
}
